package com.ruoyi.webs.utils;


import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CheckMoblleEmail {
    public static boolean isMobile(String mobile) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        String check = "^[1](([3|5|8][\\d])|([4][4,5,6,7,8,9])|([6][2,5,6,7])|([7][^9])|([9][1,8,9]))[\\d]{8}$";
        if (StringUtils.isNotBlank(mobile)) {
            p = Pattern.compile(check);
            m = p.matcher(mobile);
            b = m.matches();
        }
        return b;
    }

    public static boolean isEmail(String email) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        String check = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
        if (StringUtils.isNotBlank(email)) {
            p = Pattern.compile(check);
            m = p.matcher(email);
            b = m.matches();
        }
        return b;
    }

    public static boolean isPhone(String phone) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        String check = "^(\\d{3,4}-)?\\d{6,8}$";
        if (StringUtils.isNotBlank(phone)) {
            p = Pattern.compile(check);
            m = p.matcher(phone);
            b = m.matches();
        }
        return b;
    }

    public static void main(String[] args) {
        System.out.println("是正确格式的手机号:" + isMobile("13496215263"));
        System.out.println("是正确格式的邮箱号:" + isEmail("1321233@q"));
    }
}